//
//  ZSBlindingMoblieViewController.m
//  ZhuShou
//
//  Created by zypsusu on 15/12/26.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "ZSBlindingMoblieViewController.h"
#import "JWAnimationManager.h"

@interface ZSBlindingMoblieViewController ()
@property (weak, nonatomic) IBOutlet UILabel *moblieLabel;
@property (weak, nonatomic) IBOutlet UIButton *changeMoblieBtn;
@property (weak, nonatomic) IBOutlet UIButton *blingMobleBtn;
@property (strong, nonatomic) IBOutlet UIView *moblieView;
@property (weak, nonatomic) IBOutlet UITextField *moblieTextField;
@property (weak, nonatomic) IBOutlet UIButton *sendMessageBtn;
@property (weak, nonatomic) IBOutlet UITextField *testTextField;
@property (nonatomic, strong) JWAnimationManager *am;

@end

@implementation ZSBlindingMoblieViewController


- (IBAction)changeMoblie:(id)sender {
    // 返回上级控制器
    if ([self.delegate respondsToSelector:@selector(ZSBlindingMoblieViewControllerClickBlind)]) {
        [self.delegate ZSBlindingMoblieViewControllerClickBlind];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)blindMobile:(UIButton *)sender {
    [self.am popView:self.moblieView startLocation:JWAnimationLocation_Bottom endLocation:JWAnimationLocation_Center tapMaskBlock:^{
        [self.moblieTextField resignFirstResponder];
        [self.am removeViewFromPopView:self.moblieView toLocation:JWAnimationLocation_Bottom complationBlock:nil];
    }];
    [self.moblieTextField becomeFirstResponder];
}

- (instancetype)initWithMoblieNumber:(NSString *)number{
    self.moblieNumber = number;
    if (!self) {
        self = [super init];
    }
    return self;
}
- (IBAction)blindCannel:(id)sender {
//    [self.am removeViewFromPopView:self.moblieView toLocation:JWAnimationLocation_Bottom complationBlock:nil];
}
- (IBAction)blindMoblieClick:(id)sender {
    [self.am removeViewFromPopView:self.moblieView toLocation:JWAnimationLocation_Bottom complationBlock:nil];
    
    NSRange textRange = [self.moblieTextField.text rangeOfString:@" "];//字符串是否有空格
    if ([[self.moblieTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        [self br_AutoDisappearWithText:@"手机号码不能为空"];
    }
    else if (textRange.location != NSNotFound)
    {
        [self br_AutoDisappearWithText:@"手机号码不能包含空格"];
    }
    else if (self.testTextField.text.length < 1)
    {
        [self br_AutoDisappearWithText:@"验证码不能为空"];
    }
    else
    {
#warning todo
        
        // 上传手机号和验证码，上传成功，刷新该行
    }

}

- (IBAction)sendMoblieMessage:(id)sender {
    [self.sendMessageBtn setTitle:@"正在发送..." forState:UIControlStateNormal];
    // 获取验证码请求发送，获得验证码成功后，显示再次发送
#warning todo

}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"手机绑定";
    self.changeMoblieBtn.layer.borderWidth = 1;
    self.changeMoblieBtn.layer.borderColor = [UIColor grayColor].CGColor;
    self.blingMobleBtn.layer.borderWidth = 1;
    self.blingMobleBtn.layer.borderColor = [UIColor grayColor].CGColor;
    
    if (self.moblieNumber) {
        self.changeMoblieBtn.hidden = NO;
        self.blingMobleBtn.hidden = YES;
        self.moblieLabel.hidden = NO;
    } else {
        self.changeMoblieBtn.hidden = YES;
        self.blingMobleBtn.hidden = NO;
        self.moblieLabel.hidden = YES;
    }
    
    self.sendMessageBtn.layer.borderWidth = 1;
    self.sendMessageBtn.layer.borderColor = [UIColor grayColor].CGColor;
    
    if (!self.am) {
        self.am = [JWAnimationManager new];
        self.am.isPopViewAdaptWindowWidth = YES;
    }
    
    self.moblieTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.testTextField.keyboardType = UIKeyboardTypeNumberPad;
}

@end
